<template>
  <div class="app-container">
    <div class="big_box">
    <div class="left_box">
      <el-card class="box-card" shadow="hover" >
        <div class="mx_box" >
          <el-tabs v-model="activeName" @tab-click="handleClick" >
            <el-tab-pane label="订单记录" name="first">
                <el-table :data="tableData" border :summary-method="getSummaries" style="width: 100%">
                  <el-table-column prop="orderNumber" label="点餐单号"></el-table-column>
<!--                  <el-table-column prop="visitorId" label="游客id"></el-table-column>-->
                  <el-table-column prop="tableNumber" label="桌号"></el-table-column>
                  <el-table-column prop="entryName" label="项目名称"></el-table-column>
                  <el-table-column prop="projectCategory" label="项目类别">
                    <template slot-scope="scope">
                      <dict-tag :options="dict.type.yqg_project_category" :value="scope.row.projectCategory"/>
                    </template>
                  </el-table-column>
                  <el-table-column prop="projectCode" label="项目代码"></el-table-column>
<!--                  <el-table-column prop="mnemonicCode" label="助记码"></el-table-column>-->
                  <el-table-column prop="unit" label="单位"></el-table-column>
                  <el-table-column prop="quantity" label="数量"></el-table-column>
                  <el-table-column prop="unitPrice" label="单价"></el-table-column>
<!--                  <el-table-column prop="amount" label="合计"></el-table-column>-->
<!--                  <el-table-column label="操作"></el-table-column>-->
                </el-table>
            </el-tab-pane>
          </el-tabs>
        </div>
      </el-card>
    </div>
    </div>
  </div>
</template>

<script>
import {listOrdering} from "@/api/module/lyq/ordering";

export default {
  name: "jilu",
  dicts: ['yqg_hand_category', 'yqg_hand_state', 'yqg_payment_method', 'yqg_consumption_status', 'yqg_retention_status', 'yqg_project_category', 'yqg_post', 'yqg_check_out_status', 'yqg_department', 'yqg_merge_status', 'yqg_sailings_signs', 'yqg_next_clock_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 点餐信息暂存表格数据
      orderingList: [],
      tableData:{
        amount: null,
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 1000,
        visitorId: null,
        tableNumber: null,
        entryName: null,
        projectCategory: null,
        firstLevelClassification: null,
        secondaryClassification: null,
        tertiaryClassification: null,
        projectCode: null,
        mnemonicCode: null,
        unit: null,
        unitPrice: null,
        quantity: null,
        orderNumber: null,
        phoneTime: null,
        totalAmount: null,
        status: 0,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      activeName: 'first',
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();

  },
  methods: {
    onSubmit() {
      console.log('submit!');
    },
    handleNodeClick(data) {
      console.log(data);
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    //获取全部点餐信息
    getList() {
      this.loading = true;
      listOrdering(this.queryParams).then(response => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //指定列求和
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      //第一列命名合计
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        //指定allCompanyNum、allCarNum、allDriverNum不求和，其余列军求和
        if (column.property!=='visitorId'&& column.property!=='tableNumber'&&column.property!=='entryName'&& column.property!=='projectCategory'
          &&column.property!=='projectCode'&&  column.property !== 'mnemonicCode'&&  column.property !== 'unit'
          &&column.property !== 'quantity'&&  column.property !== 'unitPrice') {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index];
        }else{
          sums[index] = ''
        }
      });
      return sums
    }
  }
}
</script>

<style scoped>
.big_box{height: 100%;display: flex;}
.left_box{width: 100%;height: 580px;}
.mx_box{height: 580px;margin: auto}
</style>
